// pages/mainindex/index.js
import http from "../../../../class/Utils/Http"
import tips from "../../../../class/Utils/Tips"
var app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        lista: [
          {name:'微营销解决方案',imgurl:'https://toocle.y.netsun.com/xcximg/test-06.jpg',},
          {name:'供应链金融解决方案',imgurl:'https://toocle.y.netsun.com/xcximg/test-04.jpg',},
          {name:'物流网络解决方案',imgurl:'https://toocle.y.netsun.com/xcximg/test-08.jpg',},
          {name:'新流通管理软件',imgurl:'https://toocle.y.netsun.com/xcximg/test-010.jpg',}
        ],
        curNav: '1',
        showView: false,
        guanzhuzt: '关注',
        showViewb: true,
        picklist: ['供应', '求购'],
        pickkindex:'供应'
    },
    onLoad: function (get) {

        var that = this;
        that.setData({
            mid:get.mid
        })
        var user = wx.getStorageSync('user');
        http.reqload("/Mingpian/chakan", {id: get.mid, uid: user.userid}, function (infores) {

            that.setData({
                info: infores,
            })
        })
        

    },
    //点击切换
    switchRightTab: function (e) {
        var that = this;
        let id = e.target.dataset.id,
            index = parseInt(e.target.dataset.index);
        console.log(id)
        that.setData({
            curNav: id,
            prolist: [],
            page: 0,
            lock: 1,
            jiazai: 1,
            s: id
        })
        if (id == '1') {
            that.setData({
                url: "gy-mb-1"
            })
        } else {
            that.setData({
                url: "qg-mb-1"
            })
        }
        wx.pageScrollTo({
            scrollTop: 0,
            duration: 0
        })
        loadMore(that)
    },
    //监听 page 滚动条位置
    onPageScroll: function (res) {
        //console.log(res.scrollTop);
        if (res.scrollTop >= 167) {
            this.setData({
                floorstatus: true
            })
        } else {
            this.setData({
                floorstatus: false
            })
        }
    },
    //page 返回顶部 点击顶部时间未知也可返回顶部
    pagegotop: function (e) {
        wx.pageScrollTo({
            scrollTop: 0,
            duration: 300
        })
    },
    //加关注
    guanzhubtn: function (e) {
        var that = this;
        var guanzhu = that.data.showView;
        var id = e.currentTarget.dataset.id;
        console.log(id)
        var user = wx.getStorageSync('user');
        if (guanzhu == false) {
            that.setData({
                showView: (!that.data.showView),
                guanzhuzt: '已关注'
            })
            app.func.req("/Wxmain/dp_shouchang", {dpid: id, userid: user.userid}, function (res) {
                console.log(res)
            })
        } else {
            that.setData({
                showView: (!that.data.showView),
                guanzhuzt: '关注'
            })

            app.func.req("/Wxmain/dp_shouchang_del", {dpid: id, userid: user.userid})
        }

    },
    //拨打手机
    callphone: function () {
        var that = this;
        var phoneh = that.data.info.shouji
        console.log(phoneh)
        wx.makePhoneCall({
            phoneNumber: phoneh //仅为示例，并非真实的电话号码
        })
    },
    //拨打固话
    calltel: function () {
        var that = this;
        var telh = that.data.info.guhua
        wx.makePhoneCall({
            phoneNumber: telh //仅为示例，并非真实的电话号码
        })
    },
    //去首页
    gotohome:function(){
      wx.switchTab({
        url: '/pages/index/index'
      })
    },
    //去名片
    gotowodemingpian:function(e){
      wx.redirectTo({
            url: '/pages/mingpian/card/card?id='+this.data.mid
        })
      tips.goto()
    },
    // //去旺铺
    // gotowangpu:function(){
    //     wx.reLaunch({
    //         url: '/pages/mingpian/wangpu/index/index?mid='+this.data.mid
    //     })
    // },
    // //去企业介绍
    // gotojieshao:function(){
    //     wx.reLaunch({
    //         url: '/pages/mingpian/wangpu/jieshao/jieshao?mid=' + this.data.mid
    //     })
    // },
    //去旺铺
    gotowangpu:function(){
        var info = this.data.info
        if(info.wx_user.toocle_cid == 0){
            tips.error("暂无旺铺")
            return false
        }
        // if(info.wx_user.toocle_cid==100387){
        //   tips.redirectTo('/pages/mingpian/wangpu/index/index?mid='+this.data.info.id);
        // }else{
          tips.redirectTo("/pages/toocle/shop/index/index?cid="+info.wx_user.toocle_cid+"&time="+info.wx_user.toocle_ctime+"&quanmenuid=1");
        // }

    },
    //去企业介绍
    gotojieshao:function(){
        var info = this.data.info
        if(info.wx_user.toocle_cid == 0){
            tips.error("暂无旺铺")
            return false
        }
        if(info.wx_user.toocle_cid==100387){
          tips.redirectTo('/pages/mingpian/wangpu/jieshao/jieshao?mid='+this.data.info.id);
        }else{
          tips.redirectTo("/pages/toocle/shop/index/index?cid="+info.wx_user.toocle_cid+"&time="+info.wx_user.toocle_ctime+"&quanmenuid=3");
        }
    },
  //去生意宝服务中心
  // gotofuwuzhongxin: function () {
  //   tips.redirectTo('/pages/mingpian/tooclefuwu/tooclefuwu');
  // },
  //去生意宝服务中心
  gotofuwuzhongxin: function () {
    tips.godaohang('/pages/main/menu/menu');
  },


})